home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7342 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: redstone.interpath.net!mercury!softbase
  2. From: softbase@mercury.interpath.net (Scott McMahan - Softbase Systems)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Tradition or what?
  5. Date: 25 Feb 1996 19:36:57 GMT
  6. Organization: Interpath -- Providing Internet access to North Carolina
  7. Message-ID: <4gqdop$jfo@redstone.interpath.net>
  8. References: <4g0elg$mdr@redstone.interpath.net> <Dn4wML.5LJ@undergrad.math.uwaterloo.ca> <824950522snz@genesis.demon.co.uk>
  9. NNTP-Posting-Host: mercury.interpath.com
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Speaking of bizarre return values, do people realize 0 is used to mean
  13. both success, failure, and a valid return value in the standard
  14. library!? All three in the same library!
  15.  
  16. 0 means success when an error code is returned. clock() is an
  17. example -- since -1 means error, any other value is successful.
  18. (I need to go back and check, but I think this is how it works.)
  19.  
  20. 0 means failure when a valid value is returned like a pointer from
  21. malloc().
  22.  
  23. Zero is also a valid value in strcmp which can't fail (unless you pass
  24. it bogus strings and it crashes) -- 0 means equal from the set of less
  25. than, equal, and greater than.
  26.  
  27. No wonder C is confusing and error prone! Try defining a macro
  28. to represent what 0 means in the stdlib! :)
  29.  
  30. I think this is the case against explicit tests against 0 in
  31. if, while, etc expressions which decide what to do based on the
  32. return value of a function. It's much more clear if there's no
  33. explicit test against 0.
  34.  
  35. Scott
  36.  
  37.